package com.eaoa.uc.bustransfer.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.eaoa.base.EABaseAction;
import com.eaoa.constants.AttachmentConstants;
import com.eaoa.constants.PubBillConstants;
import com.eaoa.query.bus.BusTransferQuery;
import com.eaoa.uc.bustransfer.form.BusTransferForm;
import com.eaoa.utils.AttachmentUtils;
import com.eaoa.vo.bus.BusTransfer;
import com.stony.core.keygenerator.FillCodeBO;
import com.stony.core.util.CoreUtils;

public class BusTransferModifyPreAction extends EABaseAction {

	protected ActionForward doWork(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		BusTransferForm myform = (BusTransferForm) form;
		
		Long transferno = CoreUtils.parseLong(myform.getTransferno());

		if (transferno!=null) {
			if (!isReEntry(request)) {
				BusTransfer customer = BusTransferQuery.loadByNO(transferno);
				myform.setVO(customer);
			}
			Map attachments = AttachmentUtils.getAttachmentMap(AttachmentConstants.ATTACHMENTTYPE_TRANSFER,transferno);
			request.setAttribute("attachments", attachments);
		}else{
			if (!isReEntry(request)) {
				FillCodeBO codeBO = new FillCodeBO(PubBillConstants.BILLCODE_TRANSFER);
				codeBO.execute();
			    myform.setBillcode(codeBO.getNewCode());
			}
		}
		
		return mapping.findForward("success");

	}
}